package cn.t.job;

import cn.t.model.order.WorkOrderDO;
import cn.t.service.order.WorkOrderService;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;

/**
 * 5 分钟执行一次
 * @author l
 */
@Slf4j
@Component(value = "removeExpiredWorkOrderProcessJob")
public class RemoveExpiredWorkOrderProcessJob  {

    @Resource
    private WorkOrderService workOrderService;
//TODO
    public void process( ) {
        log.info("removeExpiredWorkOrderProcessJob start");
        try {
            // 0.待审批、1.待办、2.已完成、3.部分完成、4.已取消 、5.已拒绝
            List<WorkOrderDO> expiredWorkOrders = workOrderService.getWorkOrders(true, Lists.newArrayList(0,1,3));
            expiredWorkOrders.forEach(workOrderDO->{
                // 更新状态
                workOrderDO.setStatus(-1);
                this.workOrderService.update(workOrderDO);
            });
        } catch (Exception e) {
            log.error("removeExpiredWorkOrderProcessJob failed with exception", e);
        }
    }
}
